package Algorithm.Search.BlockSearch.SimgleBlock;

import java.util.Scanner;

public class Example {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int[] arr = {10, 1, 6, 9, 2,
                12, 20, 19, 17,
                21, 39, 40, 28};
        Block block1 = new Block(0, 4, 10);
        Block block2 = new Block(5, 8, 20);
        Block block3 = new Block(7, 9, 40);
        Block[] blocks = {block1, block2, block3};
        int num = sc.nextInt();
        int blockIndex = getBlockIndex(blocks, num);
        if(blockIndex == -1) {
            System.out.println("No block found");
        } else {
            for(int i = blocks[blockIndex].getStartId(); i <= blocks[blockIndex].getEndId(); i++) {
                if(arr[i] == num) {
                    System.out.println("Found block,index:"+ i);
                }
            }
        }
    }
    public static int getBlockIndex(Block[] blocks, int num) {
        for (int i = 0; i < blocks.length; i++) {
            if(num <= blocks[i].getMax()){
                return i;
            }
        }
        return -1;
    }
}

class Block{
    private int startId;
    private int endId;
    private int max;


    public Block() {
    }

    public Block(int startId, int endId, int max) {
        this.startId = startId;
        this.endId = endId;
        this.max = max;
    }

    /**
     * 获取
     * @return startId
     */
    public int getStartId() {
        return startId;
    }

    /**
     * 设置
     * @param startId
     */
    public void setStartId(int startId) {
        this.startId = startId;
    }

    /**
     * 获取
     * @return endId
     */
    public int getEndId() {
        return endId;
    }

    /**
     * 设置
     * @param endId
     */
    public void setEndId(int endId) {
        this.endId = endId;
    }

    /**
     * 获取
     * @return max
     */
    public int getMax() {
        return max;
    }

    /**
     * 设置
     * @param max
     */
    public void setMax(int max) {
        this.max = max;
    }

    public String toString() {
        return "Block{startId = " + startId + ", endId = " + endId + ", max = " + max + "}";
    }
}
